home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-16 | 4.3 KB | 149 lines | [TEXT/MPPS] |
- program Blasto;
- { A small program that blasts an 8 bit color icon to the screen.}
- { 3-6-92 By Brigham Stevens}
- { Apple Developer Technical Support}
- { 3-13-92 - BRS - Uh Oh, it's Friday the 13th}
- { Cleaned up & commented code here and there.}
- { 4-13-92 - BRS - changed icon to be self-erasing}
- { Made code somewhat better by changing names and stuff.}
- { Added comments}
- { 4-24-92 - BRS - Added ifdefs around timing code, changed names again.}
- { 11-11-92 - BRS - made a THINK C project file, and made this code work with }
- { THINK C. Also changed the date in the comment above. }
-
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- OSUtils, Windows, QDOffscreen, Retrace, Memory, Resources, Events, Menus,
- Dialogs, Fonts,
- {MPW:} OSEvents,
- {$ENDC}
- DirectScreen;
-
- {Procedure InitToolBox(numMoreMasters:Integer);}
-
- (* Amount to move icons these need to be around 1 or 2 *)
- (* or our icon will not be self erasing *)
- const
- ROW_OFF = 1;
- COL_OFF = 1;
- MAX_SECONDS = 100;
-
- {Procedure main;}
- var
- directWindow: WindowPtr;
- screenRect: Rect;
- mainScreen: GDHandle;
- mainscreenPixMap: PixMapHandle;
- colorIconHandle: Handle;
- plotLocation: Point;
- vDelta: Integer;
- hDelta: Integer;
- frameCount: LongInt;
- {ticks: LongPtr;}
- beforeTicks, afterTicks: LongInt;
- {tickTable: array[0..MAX_SECONDS] of LongInt;}
- {tickIndex: Integer;}
-
- begin
- (* Standard Witch Chant enclosed... *)
-
- {$IFC UNDEFINED THINK_PASCAL}
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- InitCursor;
- TEInit;
- FlushEvents(everyEvent, 0);
- InitDialogs(nil);
- { InitToolBox(4); (* 4 calls to MoreMasters *)
- {$ENDC}
-
- vDelta := ROW_OFF;
- hDelta := COL_OFF;
- {tickIndex := 0;}
- {Original program used the global}
- {ticks := LongPtr($16A);}
- {to get the ticks.}
- {Using the global för ticks is not a good idea. It's better to use the TickCount routine!}
-
- (* get a handle to the color icon we are drawing *)
- colorIconHandle := GetResource('icl8', 128);
- if colorIconHandle = nil then
- begin
- SysBeep(5);
- {DebugStr('Build problems: 'icl8' not loaded.');}
- halt;
- end;
-
- (* cover up the part of the screen we are writing on *)
- (* with a window, so other apps will not mess with our *)
- (* animation via update events in the background *)
- {$IFC UNDEFINED THINK_PASCAL}
- screenRect := qd.screenBits.bounds;
- {$ELSEC}
- screenRect := screenBits.bounds;
- {$ENDC}
- directWindow := NewWindow(nil, screenRect, '', true, plainDBox, WindowPtr(-1), false, 0);
-
- (* This covers up the menu bar *)
- (* and fills the screen with white *)
- SetPort(directWindow);
- RectRgn(directWindow^.visRgn, directWindow^.portRect);
- EraseRect(directWindow^.portRect);
-
- {Note: The original program created another port with OpenPort. Expanding the window's visRgn is better.}
- {Then we stay in a real window, get update events properly, can't accidentally draw in other windows,}
- {at least not with QuickDraw. Basically, we take a lot less risks.}
-
- (* get the main screen's Pix map *)
- (* Which this program expects to be 8 bits deep *)
- mainScreen := GetMainDevice;
- mainscreenPixMap := mainScreen^^.gdPMap;
-
- (* Set up a safe rectangle for bouncing off the screen *)
- screenRect.top := 4;
- screenRect.left := 4;
- screenRect.bottom := screenRect.bottom - 32;
- screenRect.right := screenRect.bottom - 32;
-
- (* loop until the mouse is clicked *)
- (* drawing and moving the color icon *)
-
- (* This is where to start drawing the color icon*)
- plotLocation.h := 100;
- plotLocation.v := 100;
- frameCount := 0;
- HideCursor;
- beforeTicks := TickCount;
-
- repeat
- begin
- (* update the location of the icon *)
- plotLocation.v := plotLocation.v + vDelta;
- plotLocation.h := plotLocation.h + hDelta;
- (* This forces us to stay on the screen *)
- if not PtInRect(plotLocation, screenRect) then
- begin
- vDelta := -vDelta; (* swap the deltas to bounce of corner *)
- hDelta := -hDelta;
- end;
- (* draw the icon *)
- DirectPlotColorIcon(LongPtr(colorIconHandle^), mainscreenPixMap, plotLocation.v, plotLocation.h);
- frameCount := frameCount + 1;
- end
- until Button;
-
- (* show the average number of frames per second for MAX_SECONDS seconds *)
- afterTicks := TickCount;
-
- ShowCursor;
-
- ParamText(stringof('Frames/sec:', (frameCount * 60 div (TickCount - beforeTicks)) : 1), '', '', '');
- if 1 = Alert(128, nil) then
- ;
-
- CloseWindow(directWindow);
- DrawMenuBar;
- FlushEvents(mDownMask, 0);
- end.